package link.gpt.service.impl;

import link.gpt.dao.EbookCategoryDao;
import link.gpt.pojo.EbookCategory;
import link.gpt.pojo.EbookCategoryExample;
import link.gpt.service.EbookCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version V1.0A
 * @uthor gpt
 * @Project holiday_task
 * @Package link.gpt.service
 * @Description: ${TODO}
 * @Date 2021/10/3 15:58
 */
@Service
public class EbookCategoryServiceImpl implements EbookCategoryService {

   @Autowired
   private EbookCategoryDao ebookCategoryDao;


   @Override
   public List<EbookCategory> findAllCategory() {
      return ebookCategoryDao.selectByExample(null);
   }

   @Override
   public EbookCategory findByName(String name) {
      EbookCategoryExample ebookCategoryExample = new EbookCategoryExample();
      EbookCategoryExample.Criteria criteria = ebookCategoryExample.createCriteria();
      criteria.andNameEqualTo(name);
      return ebookCategoryDao.selectByExample(ebookCategoryExample).get(0);
   }

   @Override
   public int insertCategory(EbookCategory ebookCategory) {
      return ebookCategoryDao.insertSelective(ebookCategory);
   }

}
